package com.itheima.tanhua.handler;

import com.itheima.tanhua.exception.ConsumerException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 芝士雪豹
 * @create 2022/9/19/15:14
 */
@RestControllerAdvice
public class MyExceptionHandler {
    //异常处理
    @ExceptionHandler(ConsumerException.class)
    public ResponseEntity consumerException(ConsumerException ex){
        ex.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ex.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ResponseEntity Exception(Exception ex){
        ex.printStackTrace();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("系统异常");
    }

}
